<?php
use Workerman\Worker;
use WebWorker\App;

require_once __DIR__.'/../../vendor/autoload.php';

!defined('ROOT') && define('ROOT', __DIR__ .'/../../');

$project = substr($dir,strrpos($dir, '/') + 1);

//加载配置文件
$cfg = require __DIR__ . '/config/config.php';
if(is_file($dir . '/config/config.php')){
    $cfg = array_merge($cfg, require_once $dir . '/config/config.php');
}

$app = new App("http://0.0.0.0:".$cfg['http']['port'], ['route_type'=>$cfg['route_type']]);

$app->name = $cfg['http']['name'];

$app->count = $cfg['http']['count'];

$app->app_namespace = "\\app\\$project";

$app->autoload = [
    __DIR__ . "/funcs/",
    __DIR__ . "/libs/",
    __DIR__ . "/models/",
    $dir . "/models/",
    $dir . "/controllers/",
    $dir . "/routes/",
];

$app->statistic_server = $cfg['statistic_server'];

$application[$project] = $app;
$config[$project] = $cfg;
$projectDir[$project] = $dir;
unset($app);
unset($cfg);
unset($dir);
unset($project);

// 如果不是在根目录启动，则运行runAll方法
if(!defined('GLOBAL_START'))
{
    Worker::$logFile = ROOT . '/cache/workerman.log';
    Worker::$pidFile = ROOT . '/cache/workerman.pid';
    Worker::runAll();
}
